#init the plugin direcoty of emacs.d

PLUGIN_DIR=$HOME/.emacs.d

if [ ! -d $PLUGIN_DIR ];then
  mkdir $PLUGIN_DIR
fi

echo $PLUGIN_DIR
cd $PLUGIN_DIR

# color-theme
#if [ ! -d color-theme-6.6.0 ];then
#  echo "download colortheme"
#  wget http://download.savannah.gnu.org/releases/color-theme/color-theme-6.6.0.tar.gz
#  tar zxf color-theme-6.6.0.tar.gz
#  ln -s $PLUGIN_DIR/color-theme-6.6.0 color-theme
#fi

# yasnippet
if [ ! -d yasnippet ];then
  echo "checkout yasnippet"
  git clone https://github.com/capitaomorte/yasnippet.git
fi

# scala
#if [ ! -d scala-mode ]; then
#  echo "check out scala"
#  svn co http://lampsvn.epfl.ch/svn-repos/scala/scala-tool-support/trunk/src/emacs/ scala-mode
#fi

# xcscope
if [ ! -f xcscope.el ]; then
  echo "download xcscope.el"
  wget http://www-inst.eecs.berkeley.edu/~cs186/fa05/debugging/xcscope.el
fi

# taglist
if [ ! -f taglist.el ]; then
  echo "download taglist.el"
  wget https://raw.github.com/frankpzh/document/master/lisp/taglist.el
fi

# auto-complete
if [ ! -d auto-complete ];then
   echo "checkout auto-complete"
   git clone https://github.com/auto-complete/auto-complete.git
   cd auto-complete
   # fix url for submodule, default is git, change to https to satisfy proxy
   git submodule init
   git config submodule.lib/ert.url https://github.com/ohler/ert.git
   git config submodule.lib/fuzzy.url https://github.com/auto-complete/fuzzy-el.git
   git config submodule.lib/popup.url https://github.com/auto-complete/popup-el.git
   git submodule update
   make byte-compile
   cp *.el *.elc ~/.emacs.d
   cp lib/popup/popup.el ~/.emacs.d
   cd $PLUGIN_DIR
fi

# autojump for eshell
if [ ! -f eshell-autojump.el ]; then
  echo "download eshell-autojump.el"
  wget http://www.emacswiki.org/emacs/download/eshell-autojump.el
fi

# js2 mode for javascript
if [ ! -f js2-mode.el -o ! -f js2.el ]; then
  echo "download js2-mode.el"
  wget https://js2-mode.googlecode.com/files/js2-mode.el
  ln -s js2-mode.el js2.el
fi

emacs -nw -batch -l ~/scripts/elisp/load_packages.el
